package com.iknow.maps;

import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import java.util.Date;
import java.util.List;
import java.util.Observable;

public class BestLocationListener extends Observable
  implements LocationListener
{
  private static final boolean DEBUG = 0;
  public static final long LOCATION_UPDATE_MAX_DELTA_THRESHOLD = 300000L;
  public static final long LOCATION_UPDATE_MIN_DISTANCE = 0L;
  public static final long LOCATION_UPDATE_MIN_TIME = 0L;
  public static final float REQUESTED_FIRST_SEARCH_ACCURACY_IN_METERS = 10000.0F;
  public static final int REQUESTED_FIRST_SEARCH_MAX_DELTA_THRESHOLD = 300000;
  public static final long SLOW_LOCATION_UPDATE_MIN_DISTANCE = 50L;
  public static final long SLOW_LOCATION_UPDATE_MIN_TIME = 300000L;
  private static final String TAG = "BestLocationListener";
  private Location mLastLocation;

  /**
   * @deprecated
   */
  public void clearLastKnownLocation()
  {
    monitorenter;
    try
    {
      this.mLastLocation = null;
      monitorexit;
      return;
    }
    finally
    {
      localObject = finally;
      monitorexit;
      throw localObject;
    }
  }

  /**
   * @deprecated
   */
  public Location getLastKnownLocation()
  {
    monitorenter;
    try
    {
      Location localLocation = this.mLastLocation;
      monitorexit;
      return localLocation;
    }
    finally
    {
      localObject = finally;
      monitorexit;
      throw localObject;
    }
  }

  public boolean isAccurateEnough(Location paramLocation)
  {
    int i;
    if ((paramLocation != null) && (paramLocation.hasAccuracy()) && (paramLocation.getAccuracy() <= 10000.0F) && (new Date().getTime() - paramLocation.getTime() < 300000L))
      i = 1;
    while (true)
    {
      return i;
      i = 0;
    }
  }

  /**
   * @deprecated
   */
  public void onBestLocationChanged(Location paramLocation)
  {
    monitorenter;
    try
    {
      this.mLastLocation = paramLocation;
      setChanged();
      notifyObservers(paramLocation);
      monitorexit;
      return;
    }
    finally
    {
      localObject = finally;
      monitorexit;
      throw localObject;
    }
  }

  public void onLocationChanged(Location paramLocation)
  {
    updateLocation(paramLocation);
  }

  public void onProviderDisabled(String paramString)
  {
  }

  public void onProviderEnabled(String paramString)
  {
  }

  public void onStatusChanged(String paramString, int paramInt, Bundle paramBundle)
  {
  }

  public void register(LocationManager paramLocationManager, boolean paramBoolean)
  {
    long l1 = 300000L;
    long l2 = 50L;
    if (paramBoolean)
    {
      l1 = 0L;
      l2 = 0L;
    }
    List localList = paramLocationManager.getProviders(true);
    int i = localList.size();
    int j = 0;
    while (true)
    {
      if (j >= i)
        return;
      String str = (String)localList.get(j);
      if (paramLocationManager.isProviderEnabled(str))
        updateLocation(paramLocationManager.getLastKnownLocation(str));
      if ((paramBoolean) || (!("gps".equals(str))))
        paramLocationManager.requestLocationUpdates(str, l1, (float)l2, this);
      ++j;
    }
  }

  public void unregister(LocationManager paramLocationManager)
  {
    paramLocationManager.removeUpdates(this);
  }

  /**
   * @deprecated
   */
  public void updateLastKnownLocation(LocationManager paramLocationManager)
  {
    int i;
    monitorenter;
    try
    {
      List localList = paramLocationManager.getProviders(true);
      i = 0;
      int j = localList.size();
      if (i >= j)
      {
        monitorexit;
        return;
      }
      String str = (String)localList.get(i);
      if (paramLocationManager.isProviderEnabled(str))
        updateLocation(paramLocationManager.getLastKnownLocation(str));
    }
    finally
    {
      monitorexit;
    }
  }

  public void updateLocation(Location paramLocation)
  {
    if ((paramLocation != null) && (this.mLastLocation == null))
      onBestLocationChanged(paramLocation);
    while (true)
    {
      int i;
      int j;
      do
      {
        int k;
        int l;
        do
          return;
        while (paramLocation == null);
        long l1 = new Date().getTime();
        long l2 = l1 - paramLocation.getTime();
        long l3 = l1 - this.mLastLocation.getTime();
        if (l2 <= 300000L)
        {
          i = 1;
          if (l3 > 300000L)
            break label160;
          j = 1;
          if (l2 > l3)
            break label166;
          if ((paramLocation.hasAccuracy()) || (this.mLastLocation.hasAccuracy()))
            break label169;
          k = 0;
          l = 0;
          if (k != 0)
          {
            if ((!(paramLocation.hasAccuracy())) || (this.mLastLocation.hasAccuracy()))
              break label175;
            l = 1;
          }
        }
        while (true)
        {
          while (true)
          {
            label131: label160: label166: 
            while (true)
              while (true)
              {
                while (true)
                {
                  while (true)
                  {
                    if ((k == 0) || (l == 0) || (i == 0))
                      break label225;
                    onBestLocationChanged(paramLocation);
                  }
                  i = 0;
                }
                j = 0;
              }
            label169: k = 1;
          }
          label175: if ((paramLocation.hasAccuracy()) || (!(this.mLastLocation.hasAccuracy())))
            break;
          l = 0;
        }
        if (paramLocation.getAccuracy() <= this.mLastLocation.getAccuracy())
          l = 1;
        while (true)
        {
          break label131:
          label225: l = 0;
        }
      }
      while ((i == 0) || (j != 0));
      onBestLocationChanged(paramLocation);
    }
  }
}